//
//  ViewController.m
//  RongCloudDemo
//
//  Created by 杜立召 on 15/4/18.
//  Copyright (c) 2015年 dlz. All rights reserved.
//

#import "XiaoxiViewController.h"
#import "ChatListViewController.h"
#import <RongIMKit/RCConversationViewController.h>
#import "XiaoTableViewCell.h"
@interface XiaoxiViewController ()<UITableViewDataSource,UITableViewDelegate>

@end

@implementation XiaoxiViewController

- (void)viewDidLoad {
    [super viewDidLoad];
//      self.navigationItem.title = @"Favourite";
    UIImage *im = [UIImage imageNamed:@"图片(1)"];
    UIImageView *o = [[UIImageView alloc] initWithFrame:CGRectMake(500, 0, 150, 50)];
    o.image = im;
    self.navigationItem.titleView = o;
//    XiaoxiViewController *i = [[XiaoxiViewController alloc] init];
//i.PreferredStatusBarStyle = UIStatusBarStyle.LightContent;
    
//    [UIViewController alloc].preferredStatusBarStyle = UIStatusBarStyleLightContent;
//    UIViewController.
        [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor blackColor]}];
    self.view.backgroundColor = [UIColor grayColor];
    UIImage *image1 = [UIImage imageNamed:@"iconfont-jiahao"];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:image1 style:UIBarButtonItemStylePlain target:self action:@selector(dede)];
    
    UITableView *table = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, 568) style:UITableViewStylePlain];
    table.delegate = self;
    table.dataSource = self;
    table.separatorStyle = UITableViewCellSeparatorStyleNone;//  分割线
    [self.view addSubview:table];
    
    NSString*token=@"qwrNmfLOUB+GSA+XtlezoVlq26DxDeEGiT13sxa3ftZxrgYPgqmGIiKW/hd+i2f3W1UdjJV8U4hVv5aaYPZtig==";
    [[RCIM sharedRCIM] connectWithToken:token success:^(NSString *userId) {
        NSLog(@"成功");
        //设置用户信息提供者,页面展现的用户头像及昵称都会从此代理取
        [[RCIM sharedRCIM] setUserInfoDataSource:self];
        NSLog(@"Login successfully with userId: %@.", userId);
        dispatch_async(dispatch_get_main_queue(), ^{
//            ChatListViewController *chatListViewController = [[ChatListViewController alloc]init];
//            [self.navigationController pushViewController:chatListViewController animated:YES];
        });
        
    } error:^(RCConnectErrorCode status) {
        NSLog(@"login error status: %ld.", (long)status);
    } tokenIncorrect:^{
        NSLog(@"token 无效 ，请确保生成token 使用的appkey 和初始化时的appkey 一致");
    }];

}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    RCConversationViewController *conversationVC = [[RCConversationViewController alloc]init];
    conversationVC.conversationType =ConversationType_PRIVATE;
    conversationVC.targetId = @"2"; //这里模拟自己给自己发消息，您可以替换成其他登录的用户的UserId
    conversationVC.userName = @"客官大大";
    conversationVC.title = @"biu";
                conversationVC.hidesBottomBarWhenPushed=YES;
    [self.navigationController pushViewController:conversationVC animated:YES];
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    
    
    static NSString *indent = @"cell";
    XiaoTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:indent];
    if (cell == nil) {
        cell = [[[NSBundle mainBundle] loadNibNamed:@"XiaoTableViewCell" owner:self options:nil]lastObject];
                  [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    }
    if (indexPath.section == 0) {
        cell.name.text = @"大连东软信息学院";
        cell.neirogn.text = @"咱们群明天聚会，谁能去";
        UIImage *image = [UIImage imageNamed:@"9a504fc2d56285355d9828c590ef76c6a6ef63de.jpg"];
        cell.touxiang.image = image;
        
    }
    return cell;
    
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 18;
}
// 分区的高度

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 10;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 61;
}

/**
 *登录融云
 *
 */
-(void)dede
{

}
-(void)loginRongCloud
{
    //登录融云服务器,开始阶段可以先从融云API调试网站获取，之后token需要通过服务器到融云服务器取。

    
}
/**
 *此方法中要提供给融云用户的信息，建议缓存到本地，然后改方法每次从您的缓存返回
 */
- (void)getUserInfoWithUserId:(NSString *)userId completion:(void(^)(RCUserInfo* userInfo))completion
{
    //此处为了演示写了一个用户信息
    if ([@"1" isEqual:userId]) {
        RCUserInfo *user = [[RCUserInfo alloc]init];
        user.userId = @"1";
        user.name = @"客官大大";
        user.portraitUri = @"https://ss0.baidu.com/73t1bjeh1BF3odCf/it/u=1756054607,4047938258&fm=96&s=94D712D20AA1875519EB37BE0300C008";
        
        return completion(user);
    }else if([@"2" isEqual:userId]) {
        RCUserInfo *user = [[RCUserInfo alloc]init];
        user.userId = @"2";
        user.name = @"测试2";
        user.portraitUri = @"https://ss0.baidu.com/73t1bjeh1BF3odCf/it/u=1756054607,4047938258&fm=96&s=94D712D20AA1875519EB37BE0300C008";
        return completion(user);
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
